package cn.fay.chapter11;

import java.util.LinkedList;
import java.util.Queue;

public class Test27 {

	
	public static void main(String[] args) {
		Command command1=new Command("command1");
		Command command2=new Command("command2");
		Command command3=new Command("command3");
		Command command4=new Command("command4");
		Qcmd qcmd=new Qcmd();
		qcmd.addCmd(command1);
		qcmd.addCmd(command2);
		qcmd.addCmd(command3);
		qcmd.addCmd(command4);
		Queue<Command> queue=qcmd.sendQ();
	}

}
class Command{
	private String command;
	public Command(String command){
		this.command=command;
	}
	public void operation(){
		System.out.println(command);
	}
}
class Qcmd{
	private Queue<Command> queue=new LinkedList<Command>();
	public Command addCmd(Command command){
		queue.offer(command);
		return command;
	}
	public Queue sendQ(){
		while(queue.peek()!=null)
		{
			Command command = queue.remove();
			command.operation();
		}
		return queue;
	}
	
}